/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ConfigDatabse.java
 *
 * Created on Jul 19, 2011, 10:54:06 PM
 */
package com.viweb.storemanager.ui.config;

import com.viweb.storemanager.entity.DatabaseConfig;
import com.viweb.storemanager.ui.MainFrm;

/**
 *
 * @author qhvic
 */
public class ConfigDatabase extends javax.swing.JPanel {

    private String validDescription;
    private DatabaseConfig databaseConfig;

    /** Creates new form ConfigDatabse */
    public ConfigDatabase() {
        this.databaseConfig = MainFrm.APP_CONFIG.getDatabaseConfig();
        initComponents();
    }

    public boolean updateConfig() {
        if (this.txtUsername.getText().trim().equals("")) {
            this.setValidDescription("Chưa thiết lập thông tin tên tài khoản!");
            return false;
        }

        if (String.valueOf(this.txtPassword.getPassword()).trim().equals("")) {
            this.setValidDescription("Chưa thiết lập thông tin mật khẩu!");
            return false;
        }

        if (this.txtServername.getText().trim().equals("")) {
            this.setValidDescription("Chưa thiết lập thông tin server!");
            return false;
        }

        if (this.txtPort.getText().trim().equals("")) {
            this.setValidDescription("Chưa thiết lập thông tin cổng!");
            return false;
        }

        databaseConfig.setUsername(this.txtUsername.getText().trim());
        databaseConfig.setPassword(String.valueOf(this.txtPassword.getPassword()).trim());
        databaseConfig.setServername(this.txtServername.getText().trim());
        databaseConfig.setPort(this.txtPort.getText().trim());

        return true;
    }

    public String getValidDescription() {
        return validDescription;
    }

    public void setValidDescription(String validDescription) {
        this.validDescription = validDescription;
    }

    @Override
    public void requestFocus() {
        this.txtUsername.requestFocus();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        lblTitle = new javax.swing.JLabel();
        pnlDatabseInfo = new javax.swing.JPanel();
        lblDatabaseInfo = new javax.swing.JLabel();
        sep1 = new javax.swing.JSeparator();
        pnlInfo = new javax.swing.JPanel();
        lblUsername = new javax.swing.JLabel();
        lblPassword = new javax.swing.JLabel();
        lblServername = new javax.swing.JLabel();
        lblDatabasename = new javax.swing.JLabel();
        lblPort = new javax.swing.JLabel();
        txtUsername = new javax.swing.JTextField();
        txtPassword = new javax.swing.JPasswordField();
        txtServername = new javax.swing.JTextField();
        txtPort = new javax.swing.JFormattedTextField();
        cbbDatabasename = new javax.swing.JComboBox();

        setLayout(new java.awt.GridBagLayout());

        lblTitle.setBackground(new java.awt.Color(153, 0, 102));
        lblTitle.setFont(new java.awt.Font("Tahoma", 1, 14));
        lblTitle.setForeground(new java.awt.Color(0, 0, 204));
        lblTitle.setText(" Thiết lập dữ liệu");
        lblTitle.setMaximumSize(new java.awt.Dimension(129, 30));
        lblTitle.setMinimumSize(new java.awt.Dimension(129, 30));
        lblTitle.setPreferredSize(new java.awt.Dimension(129, 30));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 5, 0);
        add(lblTitle, gridBagConstraints);

        pnlDatabseInfo.setLayout(new java.awt.GridBagLayout());

        lblDatabaseInfo.setText("Thông tin dữ liệu");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        pnlDatabseInfo.add(lblDatabaseInfo, gridBagConstraints);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 0);
        pnlDatabseInfo.add(sep1, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 5, 10, 5);
        add(pnlDatabseInfo, gridBagConstraints);

        pnlInfo.setLayout(new java.awt.GridBagLayout());

        lblUsername.setText("Tên tài khoản:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 15, 5, 0);
        pnlInfo.add(lblUsername, gridBagConstraints);

        lblPassword.setText("Mật khẩu:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 15, 5, 0);
        pnlInfo.add(lblPassword, gridBagConstraints);

        lblServername.setText("Tên server:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 15, 5, 0);
        pnlInfo.add(lblServername, gridBagConstraints);

        lblDatabasename.setText("Tên database: ");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 15, 5, 0);
        pnlInfo.add(lblDatabasename, gridBagConstraints);

        lblPort.setText("Cổng:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 15, 5, 0);
        pnlInfo.add(lblPort, gridBagConstraints);

        txtUsername.setMinimumSize(new java.awt.Dimension(200, 25));
        txtUsername.setPreferredSize(new java.awt.Dimension(200, 25));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 5);
        pnlInfo.add(txtUsername, gridBagConstraints);

        txtPassword.setMinimumSize(new java.awt.Dimension(200, 25));
        txtPassword.setPreferredSize(new java.awt.Dimension(200, 25));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 5);
        pnlInfo.add(txtPassword, gridBagConstraints);

        txtServername.setMinimumSize(new java.awt.Dimension(200, 25));
        txtServername.setPreferredSize(new java.awt.Dimension(200, 25));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 5);
        pnlInfo.add(txtServername, gridBagConstraints);

        txtPort.setMinimumSize(new java.awt.Dimension(100, 25));
        txtPort.setPreferredSize(new java.awt.Dimension(100, 25));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 5);
        pnlInfo.add(txtPort, gridBagConstraints);

        cbbDatabasename.setMinimumSize(new java.awt.Dimension(200, 25));
        cbbDatabasename.setPreferredSize(new java.awt.Dimension(200, 25));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 5);
        pnlInfo.add(cbbDatabasename, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 5);
        add(pnlInfo, gridBagConstraints);
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox cbbDatabasename;
    private javax.swing.JLabel lblDatabaseInfo;
    private javax.swing.JLabel lblDatabasename;
    private javax.swing.JLabel lblPassword;
    private javax.swing.JLabel lblPort;
    private javax.swing.JLabel lblServername;
    private javax.swing.JLabel lblTitle;
    private javax.swing.JLabel lblUsername;
    private javax.swing.JPanel pnlDatabseInfo;
    private javax.swing.JPanel pnlInfo;
    private javax.swing.JSeparator sep1;
    private javax.swing.JPasswordField txtPassword;
    private javax.swing.JFormattedTextField txtPort;
    private javax.swing.JTextField txtServername;
    private javax.swing.JTextField txtUsername;
    // End of variables declaration//GEN-END:variables
}
